home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 January: Mac OS SDK / Dev.CD Jan 00 SDK2.toast / What's New / • What was new 11⁄99 / Sample Code / Overview / Optimization TN Demos / CBuffFileStream / CBuffFileStream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-13  |  2.3 KB  |  78 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        CBuffFileStream.h
  3.  
  4.     Contains:    Buffer handling.
  5.  
  6.     Written by:    Tim Carroll
  7.  
  8.     Copyright:    Copyright (c) 1999 Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18. */
  19.  
  20. #pragma once
  21.  
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25.  
  26. enum
  27. {
  28.     eBuffFileStreamBufferMaxSize = 4096
  29. };
  30. enum
  31. {
  32.     eBuffFileStreamIamReading,
  33.     eBuffFileStreamIamWriting
  34. };
  35.  
  36. typedef struct CBuffFileStreamData
  37. {
  38. // This is a buffer which we will slide around as a window into the file
  39.     char                        mFileWindow[eBuffFileStreamBufferMaxSize];
  40.  
  41. // This is the file ref num of the opened file
  42.     short                        mFileRefNum;
  43.  
  44. // The current length of the buffer. This cannot exceed the maximum size
  45.     unsigned                    mBufferLength;
  46.  
  47. // The offset into the buffer where we are currently reading from
  48.     unsigned                    mBufferCurPos;
  49.  
  50. // The offset into the file where the window begins
  51. // This is used only to adjust our location when we flush the buffer
  52.     long                        mWindowLocation;
  53.  
  54. // The permissions we have for accessing the file
  55. // This is determined upon open, however it can change if things
  56. // change behind our back.
  57.     short                        mFilePerms;
  58.  
  59. // Whether or not the buffer we have is for writing
  60.     int                            mBufferMode;
  61.  
  62. } CBuffFileStreamData;
  63.  
  64. OSErr    BFSOpenFile(CBuffFileStreamData **newdata, FSSpec *inFileInfo, long inPrivileges);
  65. OSErr    BFSCloseFile(CBuffFileStreamData *fdata);
  66. OSErr    BFSSetMarker(CBuffFileStreamData *fdata, long inOffset, long fromWhere);
  67. long    BFSGetMarker(CBuffFileStreamData *fdata);
  68. OSErr    BFSSetLength(CBuffFileStreamData *fdata, long inLength);
  69. long    BFSGetLength(CBuffFileStreamData *fdata);
  70. OSErr    BFSWrite(CBuffFileStreamData *fdata, long *writeAmt, const void *inBuffer);
  71. OSErr    BFSRead(CBuffFileStreamData *fdata, long *readAmt, void *outBuffer);
  72. long    BFSGetFilePermissions(CBuffFileStreamData *fdata);
  73. OSErr    BFSFlushFile(CBuffFileStreamData *fdata);
  74.  
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78.